package userprofile;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import it.cnr.icib.XSBProlog.XSBProlog;


//-import XSBProlog.XSBProlog;

import Java2XSB.Evento;

public class UserProfile {

	private TourPeriod tourPeriod;
	private List<Preference> preference;
	private int enjoyWalking;
	private int tourTime;
	private List<Evento> events;

	public UserProfile() {
		// Inizializza il profilo con valori di default

		this.setTourPeriod(new TourPeriod());

		this.setEnjoyWalking(1); // Medio

		this.setTourTime(3);

		this.setPreference(new ArrayList<Preference>());
		this.getPreference().add(new Preference("chiese"));
		this.getPreference().add(new Preference("musei"));
		this.getPreference().add(new Preference("palazzi"));
		this.getPreference().add(new Preference("giardini"));
		this.getPreference().add(new Preference("piazze"));
		this.getPreference().add(new Preference("castelli"));

		this.events = new ArrayList<Evento>();
	}

	public UserProfile(int type) {
		// Inizializza il profilo con valori di default

		switch (type){
			case 0: this.setTourPeriod(new TourPeriod());	this.setEnjoyWalking(1); /* Medio*/		this.setTourTime(3);
					this.setPreference(new ArrayList<Preference>());	 this.getPreference().add(new Preference("chiese"));
					this.getPreference().add(new Preference("musei"));	 this.getPreference().add(new Preference("palazzi"));
					this.getPreference().add(new Preference("giardini")); this.getPreference().add(new Preference("piazze"));
					this.getPreference().add(new Preference("castelli")); this.events = new ArrayList<Evento>();;
			
			case 1: this.setTourPeriod(new TourPeriod(1));	this.setEnjoyWalking(1); /* Medio*/		this.setTourTime(3);
					this.setPreference(new ArrayList<Preference>());	 this.getPreference().add(new Preference("chiese"));
					this.getPreference().add(new Preference("musei"));	 this.getPreference().add(new Preference("palazzi"));
					this.getPreference().add(new Preference("giardini")); this.getPreference().add(new Preference("piazze"));
					this.getPreference().add(new Preference("castelli")); this.events = new ArrayList<Evento>();;;
			
			case 2: this.setTourPeriod(new TourPeriod(2));	this.setEnjoyWalking(1); /* Medio*/		this.setTourTime(3);
					this.setPreference(new ArrayList<Preference>());	 this.getPreference().add(new Preference("chiese"));
					this.getPreference().add(new Preference("musei"));	 this.getPreference().add(new Preference("palazzi"));
					this.getPreference().add(new Preference("giardini")); this.getPreference().add(new Preference("piazze"));
					this.getPreference().add(new Preference("castelli")); this.events = new ArrayList<Evento>();;;
			
			case 3: this.setTourPeriod(new TourPeriod(3));	this.setEnjoyWalking(1); /* Medio*/		this.setTourTime(3);
					this.setPreference(new ArrayList<Preference>());	 this.getPreference().add(new Preference("chiese"));
					this.getPreference().add(new Preference("musei"));	 this.getPreference().add(new Preference("palazzi"));
					this.getPreference().add(new Preference("giardini")); this.getPreference().add(new Preference("piazze"));
					this.getPreference().add(new Preference("castelli")); this.events = new ArrayList<Evento>();;;
			
		}
	}

	public void AssertProfilo(XSBProlog prolog) {

		// Object[][] preferenze = parent.getPreferenze();
		// int PiacerePasseggiare = parent.getPiacerePasseggiare();
		// int TempoVisita = parent.getTempoVisita();
		// int[] IdEventiSelezionati = parent.getIdEventiselezionati();

		prolog.RetractGoal("periodo(_,_)", true);
		int gga = this.getTourPeriod().getStartDate().get(Calendar.DAY_OF_MONTH);
		int mma = this.getTourPeriod().getStartDate().get(Calendar.MONTH) + 1;
		int aaa = this.getTourPeriod().getStartDate().get(Calendar.YEAR);

		int ggp = this.getTourPeriod().getEndDate().get(Calendar.DAY_OF_MONTH);
		int mmp = this.getTourPeriod().getEndDate().get(Calendar.MONTH) + 1;
		int aap = this.getTourPeriod().getEndDate().get(Calendar.YEAR);

		if (prolog.deterministicGoal("assert(periodo([" + gga + "," + mma + ","
				+ aaa + "],[" + ggp + "," + mmp + "," + aap + "]))"))
			// System.out.println("Periodo ok");
			;
		else
			System.out.println("Periodo non ok");

		prolog.RetractGoal("preferenza(_,_)", true);
		for (int i = 0; i < getPreference().size(); i++) {
			if (prolog.AssertGoal("preferenza("
					+ getPreference().get(i).getTipologia() + ","
					+ getPreference().get(i).getValue() + ")"))
				// System.out.println("Assert preferenza ok");
				;
			else
				System.out.println("Assert preferenza not ok");
		}

		prolog.RetractGoal("piacerePasseggiare(_)", true);
		if (prolog.AssertGoal("piacerePasseggiare(" + this.getEnjoyWalking() + ")"))
			// System.out.println("Assert piacerePasseggiare ok");
			;
		else
			System.out.println("Assert piacerePasseggiare not ok");

		prolog.RetractGoal("oreVisita(_)", true);
		if (prolog.AssertGoal("oreVisita(" + this.getTourTime() + ")"))
			// System.out.println("Assert oreVisita ok");
			;
		else
			System.out.println("Assert oreVisita not ok");

		prolog.AssertaGoal("evento(_)");
		prolog.RetractGoal("evento(_)", true);
		if (events.size() != 0) {
			// System.out.println(IdEventiSelezionati.length);
			for (int i = 0; i < events.size(); i++) {
				if (prolog.AssertGoal("evento(" + events.get(i).getId() + ")"))
					// System.out.println("Assert evento ok");
					;
				else
					System.out.println("Assert evento not ok");
			}

		}

	}

	public TourPeriod getTourPeriod() {
		return tourPeriod;
	}

	public void setTourPeriod(TourPeriod tourPeriod) {
		this.tourPeriod = tourPeriod;
	}

	public List<Preference> getPreference() {
		return preference;
	}

	public void setPreference(List<Preference> preference) {
		this.preference = preference;
	}

	public int getEnjoyWalking() {
		return enjoyWalking;
	}

	public void setEnjoyWalking(int enjoyWalking) {
		this.enjoyWalking = enjoyWalking;
	}

	public int getTourTime() {
		return tourTime;
	}

	public void setTourTime(int tourTime) {
		this.tourTime = tourTime;
	}

}
